<template>

  <div class="login_container">
    <div class ="login_box">
      <div class="avatar_box">
<!--        <img src="../assets/logo.png" alt="">-->
      </div>
  <el-container>
<!--    <el-header class="head1">教学管理系统</el-header>-->
    <el-main>
<h1>教学管理系统</h1>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="0px" class="demo-ruleForm">

        <el-form-item  prop="idPass" >
          <el-input
              type="id"
              v-model="ruleForm.idPass"
              autocomplete="off"
              prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>

        <el-form-item  prop="pass" >
        <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
            show-password
            prefix-icon="el-icon-lock"
        >
        </el-input>
      </el-form-item>

        <el-form-item class ="btns">
          <el-button type="primary" @click="submitForm">登陆</el-button>
        </el-form-item>
      </el-form>
    </el-main>
  </el-container>
    </div>
  </div>

</template>

<script>
export default {

  data() {


    return {
      username:global.username,
      ruleForm: {
        pass: '',
        idPass: '',
      },
      rules: {
        pass: [
          { required:true,message:'请输入密码', trigger: 'blur' }
        ],
        idPass: [
          { required:true,message:'请输入用户名', trigger: 'blur' }
        ],

      }
    };
  },
  methods: {
    submitForm() {

      this.$refs.ruleForm.validate( async valid => {

         if (valid) {
           const{data: res }=await this.$http.get("login",{params:{
             idPass:this.ruleForm.idPass,
             pass:this.ruleForm.pass},
           });
           if(res.state!=200) this.$message.error("登陆失败！");
            else {
             this.$message.success("登陆成功！");
             username = res.data.id;
             this.$router.push("/success");
           }

      }});
    },
  }
}
</script>

<style lang="less" scoped>

.login_container{
  background-image: repeating-linear-gradient(to right,#3a7bd5,#3a6073);
  height: 100%;
}
.login_box{
  width:450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left:50%;
  top:50%;
  transform: translate(-50%,-50%);
}
.demo-ruleForm{
  position: absolute;
  bottom: 0;
  width:90%;
  padding:0 20px;
  box-sizing: border-box;

}

.btns{
  display: flex;
  justify-content: flex-end;
}
</style>